<template>
	<view class="page">
		<q-navbar title="生产投入" :isBack="false"></q-navbar>
		<view class="center">
			<view class="list-box">
				<view class="list-info">
					<item v-for="(v,i) in list" :key="i" :info="v"></item>
					<!-- 加载更多 -->
					<u-loadmore :status="status" v-if="list[0]" @loadmore='more' />
					<!-- 数据为空 -->
					<u-empty mode="list" v-if="!list[0]"></u-empty>
				</view>
			</view>

			<view class="top-btn">
				<view class="add-btn">
					<!-- <u-button type="primary" shape="square" size="medium" :plain="true">录 入
						信 息</u-button> -->
          <q-button :isPosition='false' name='录 入 信 息' @submit="router.push({
					path: '/pages/index/Form/index' })"></q-button>
          <u-button  plain @click="logout">退出登录</u-button>
				</view>
				<view class="QrCode-btn" v-if="false">
					<u-icon name="scan" color="#2979ff" size="56" @click="router.push({
					path: '/pages/QRCode/index'
				})"></u-icon>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import QRcode from '../components/QRcode.vue'
	import item from '../components/listItem.vue'
  import  s from '@/utils/storage'
	export default {
		components: {
			QRcode,
			item
		},
		props: {},
		data() {
			return {
				queryParams: {
					pageNum: 1,
					pageSize: 2,
					agentName: null,
					typeId: null,
				},
				list: [],
				status: 'loadmore',
				total: ''
			}
		},
		watch: {},
		// 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
		onReady() {},
		onLoad(options) {
			this.findList(1)
		},
		onShow() {},
		methods: {
			findList(e) {
				console.log('this.queryParams', this.queryParams);
				this.$api.listAgricultural(this.queryParams).then(res => {
					this.status = 'loadmore'

					if (e) {
						this.list = res.rows
						this.total = res.total
					} else {
						this.list.push(...res.rows)
					}
					if (this.list.length == this.total) {
						this.status = 'nomore'
					} else {
						this.status = 'loadmore'
					}
				})
			},
      logout(){
           uni.showModal({
              title: '确定退出登录吗？',
              showCancel: true,
              success: (res) => {
                  if (res.confirm) {
                        s.clearAll()
                      uni.reLaunch({
                          url: '/pages/login/new_file'
                      })
                  }
                }
           })
      },
			// 加载
			onReachBottom() {
				if (this.list.length == this.total) return;
				this.status = 'loading';
				this.requestParams.pageNum += 1;
				this.findList();
			},
			more() {
				if (this.list.length == this.total) return;
				this.status = 'loading';
				this._data.queryParams.pageNum += 1
				this.findList()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		height: 100vh;
		width: 100vw;
		background-color: #f7f7f7;
		overflow: hidden;

		.center {
			width: 95%;
			height: 100%;
			margin: 0rpx auto 0;

			.top-btn {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.add-btn {
					flex: 1;
					margin-right: 20rpx;
				}

				.QrCode-btn {}
			}

			.list-box {
				height: 75%;
				background-color: #fff;
				border-radius: 30rpx;
				width: 100%;
				margin: 20rpx 0;
				padding: 20rpx 20rpx;

				.list-info {
					height: 100%;
					overflow-y: auto;
					padding-bottom: 100rpx;
				}

			}
		}
	}
</style>